// pages/my/index.js
import {
    user,
    wxapp,
    position
} from "../../api/apiData"
Page({

    /**
     * 页面的初始数据
     */
    data: {
        info:'',
        type: "",
        myinfo: '',
        is_shrink: false,
        showNav: false,
        showImg: false,
        banner: '/images/mine/banner.png',
        navList: [{
                url: "/pages/order/index",
                src: "/images/mine/icon1.png",
                name: "我的订单"
            },
            {
                url: "/pages/my/comment",
                src: "/images/mine/icon2.png",
                name: "我的评价"
            },
            {
                url: "/pages/shopping/address",
                src: "/images/mine/icon3.png",
                name: "我的地址"
            }
        ],
        navList2: [
            // {
            //     url: "/pages/npcNews/index",
            //     src: "/images/mine/icon4.png",
            //     name: "分享邀请"
            // },
            // {
            //     url: "/pages/contact/index",
            //     src: "/images/mine/icon5.png",
            //     name: "民宿入驻"
            // },
            // {
            //     url: "/pages/car/resign",
            //     src: "/images/mine/icon6.png",
            //     name: "司机入驻"
            // },
            // {
            //     url: "/pages/my/info",
            //     src: "/images/mine/icon7.png",
            //     name: "个人资料"
            // },
            // {
            //     url: "/pages/collect/index",
            //     src: "/images/mine/icon8.png",
            //     name: "我的收藏"
            // },
            // {
            //     url: "/pages/my/feed",
            //     src: "/images/mine/icon10.png",
            //     name: "问题反馈"
            // },
            // {
            //     url: "/pages/coupon/list",
            //     src: "/images/mine/icon12.png",
            //     name: "我的卡包"
            // },
            // {
            //     url: "/pages/manage/index",
            //     src: "/images/mine/icon7.png",
            //     name: "核销端"
            // },
            // {
            //     url: "/pages/integral/index",
            //     src: "/images/mine/icon4.png",
            //     name: "体验活动"
            // }
        ],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        position.content.lists({
			position_id: 6
		}, res => {
			if (res.code == 1) {
				this.setData({
					navList2: res.data
				})

			} else {
				wx.showToast({
					title: res.msg,
					icon: 'error'
				})
			}
		})
    },
    	/**
	 * 授权登录
	 */
	getUserInfos(e) {
        let that = this
		wx.login({
			success(res) {
				console.log(res)
				let code = res.code
				wx.getUserInfo({
					success: (res) => {
						var encryptedData = res.encryptedData;
						var iv = res.iv
						var info = res.rawData
						var obj = {
							code: code,
							iv: iv,
							encryptedData: encryptedData
						}
						wxapp.login(obj, res => {
							if (res.code == 1) {
								wx.setStorage({
									key: "token",
									data: res.data.token
                                })
                                that.getInfo()
							} else {
								wx.showToast({
									title: res.msg,
									icon: 'none'
								})
							}
						})
					},
					fail: res => {

					}
				})
			}
		})
	},
    toLogin() {
        wx.navigateTo({
            url: '/pages/login/wxLogin',
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        this.getInfo()
    },
    getInfo() {
        let token = wx.getStorageSync('token')
        if (token) {
            // 获取用户详情
            user.detailS({}, res => {
                if(res.code==20003){
					this.getUserInfos()
                }else{
                    this.setData({
                        info: res.data
                    })
                }
                
            })
        } else {
			this.getUserInfos()

        }
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    },



})